package o;

import android.net.ConnectivityManager;
import android.net.LinkProperties;
import android.net.Network;
import android.net.NetworkInfo;
import android.net.RouteInfo;
import com.huawei.hwCloudJs.d.d;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.net.InetAddress;
import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

public class cmt extends cmu {
    private int ˊ = 2;
    private Map<String, String> ˎ = new HashMap();

    public cmt(cmq o_cmq) {
        super(o_cmq, "DeviceInfoTask");
    }

    public void run() {
        ॱ();
        ˊ();
        ˏ();
        ˎ();
        this.ˋ.ˊ(-103, this.ˊ, ˋ());
    }

    private String ˋ() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("Device Info Test\n");
        for (Entry entry : this.ˎ.entrySet()) {
            stringBuilder.append("[").append((String) entry.getKey()).append("]:[").append((String) entry.getValue()).append("]\n");
        }
        return stringBuilder.toString();
    }

    private void ॱ() {
        StringBuilder stringBuilder = new StringBuilder();
        StringBuilder stringBuilder2 = new StringBuilder();
        ConnectivityManager connectivityManager = (ConnectivityManager) this.ˋ.ˎ().getSystemService("connectivity");
        NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
        if (activeNetworkInfo != null) {
            for (Network network : connectivityManager.getAllNetworks()) {
                if (connectivityManager.getNetworkInfo(network).getType() == activeNetworkInfo.getType()) {
                    LinkProperties linkProperties = connectivityManager.getLinkProperties(network);
                    for (InetAddress inetAddress : linkProperties.getDnsServers()) {
                        if (inetAddress.getHostAddress() != null) {
                            stringBuilder.append(inetAddress.getHostAddress()).append(", ");
                        }
                    }
                    for (RouteInfo gateway : linkProperties.getRoutes()) {
                        stringBuilder2.append(gateway.getGateway().getHostAddress()).append(", ");
                    }
                }
            }
        } else {
            this.ˊ = 1;
        }
        this.ˎ.put("dns ip", stringBuilder.toString());
        this.ˎ.put("gateway", stringBuilder2.toString());
    }

    private void ˏ() {
        Object obj;
        String str = HwAccountConstants.NULL;
        String ˏ;
        try {
            Enumeration networkInterfaces = NetworkInterface.getNetworkInterfaces();
            while (networkInterfaces.hasMoreElements()) {
                NetworkInterface networkInterface = (NetworkInterface) networkInterfaces.nextElement();
                if (networkInterface.isUp()) {
                    for (InterfaceAddress interfaceAddress : networkInterface.getInterfaceAddresses()) {
                        InetAddress address = interfaceAddress.getAddress();
                        if (!address.isLoopbackAddress()) {
                            String hostAddress = address.getHostAddress();
                            if (!hostAddress.contains(":") || hostAddress.indexOf(":") == 0) {
                                ˏ = ˏ(interfaceAddress.getNetworkPrefixLength());
                                str = ˏ;
                            }
                        }
                        ˏ = str;
                        str = ˏ;
                    }
                }
            }
            obj = str;
        } catch (Exception e) {
            Exception exception = e;
            ˏ = str;
            cmp.ˊ.ˊ("DeviceInfoTask", "getMask failed, exception:" + exception.toString());
        }
        this.ˎ.put("mask", obj);
    }

    private String ˏ(int i) {
        int i2;
        int i3 = -1 << (32 - i);
        int[] iArr = new int[4];
        for (i2 = 0; i2 < iArr.length; i2++) {
            iArr[(iArr.length - 1) - i2] = (i3 >> (i2 * 8)) & 255;
        }
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(iArr[0]);
        for (i2 = 1; i2 < iArr.length; i2++) {
            stringBuilder.append(".").append(iArr[i2]);
        }
        return stringBuilder.toString();
    }

    private void ˊ() {
        Object obj;
        switch (doo.ʼ(this.ˋ.ˎ())) {
            case 1:
                obj = d.f;
                break;
            case 2:
                obj = "2G";
                break;
            case 3:
                obj = "3G";
                break;
            case 4:
                obj = "4G";
                break;
            case 5:
                obj = "5G";
                break;
            default:
                obj = d.b;
                this.ˊ = 1;
                break;
        }
        this.ˎ.put("network type", obj);
    }

    private void ˎ() {
        ॱ("init.svc.mdnsd");
        ॱ("ro.config.dnscure_ipcfg");
        ॱ("net.rmnet0.dns1");
        ॱ("net.qtaguid_enabled");
        ॱ("hw.wifi.dns_stat");
        ॱ("hw.wifipro.dns_fail_count");
        ॱ("hw.wifipro.uid_dns_fail_count");
        ॱ("wifi.interface");
        ॱ("wifi.direct.interface");
        ॱ("net.rmnet0.dns1");
        ॱ("gsm.network.type");
    }

    private void ॱ(String str) {
        this.ˎ.put(str, cnr.ˏ(str, HwAccountConstants.NULL));
    }
}
